package hust.game.screen;

import hust.game.stages.DragDropStage;

import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;

public class HomeScreen extends AbstractScreen {
	private MyStage stage;

	public HomeScreen () {
		stage = new MyStage();
		
		TextureAtlas bgAtlas = game.manager.get("background/background.pack", TextureAtlas.class);
		TextureAtlas uiAtlas = game.manager.get("ui/ui.pack", TextureAtlas.class);
		
		Image backgound = new Image(bgAtlas.findRegion("backgroung"));
		backgound.setFillParent(true);
		stage.addActor(backgound);
		
		Image playgame = new Image(uiAtlas.findRegion("btnPlay"));
		playgame.setPosition(game.convertWidth(567), game.convertHeight(45));
		stage.addActor(playgame);
		
		playgame.addListener(new ClickListener() {
			@Override
			public void clicked(InputEvent event, float x, float y) {
				super.clicked(event, x, y);
				game.setScreen(new GameScreen());
			}
		});
		
		Image btn1 = new Image(uiAtlas.findRegion("archery"));
		btn1.setPosition(game.convertWidth(-200), game.convertHeight(147));
		btn1.addAction(Actions.moveTo(333, 147, 1));
		stage.addActor(btn1);
		
		Image btn2 = new Image(uiAtlas.findRegion("olympic"));
		btn2.setPosition(game.convertWidth(-200), game.convertHeight(252));
		btn2.addAction(Actions.moveTo(212, 252, 1));
		stage.addActor(btn2);
		
		Image btn3 = new Image(uiAtlas.findRegion("london"));
		btn3.setPosition(game.convertWidth(-200), game.convertHeight(383));
		btn3.addAction(Actions.moveTo(46, 383, 1));
		stage.addActor(btn3);
		
		Image anhbia1 = new Image(uiAtlas.findRegion("Untitled-1"));
		anhbia1.setPosition(game.convertWidth(0), game.convertHeight(0));
		stage.addActor(anhbia1);
		
		Image anhbia2 = new Image(uiAtlas.findRegion("shape130.svg"));
		anhbia2.setPosition(game.convertWidth(472), game.convertHeight(257));
		stage.addActor(anhbia2);
	}
	@Override
	public Stage getStage() {
		// TODO Auto-generated method stub
		return stage;
	}
	
	public static HomeScreen instance = null;

	public static Screen getInstance() {
		if (instance == null) {
			instance = new HomeScreen();
		}
		return instance;
	}
	
	class MyStage extends DragDropStage {

		public MyStage() {
			super(game.assumeWidth, game.assumeHeight, false);
			// TODO Auto-generated constructor stub
		}
	}
}
